function twoSum(nums, target) {
    let first = 0
    let second = nums.length - 1
    while(first < second ) {
        if (nums[first] + nums[second] !== target) {
            first++
            if (first === second) {
                second--
                first = 0
            }
        } else {
            return [first, second]
        }
    }
}

const nums = [3,2,4]
const target = 6

console.log(twoSum(nums, target))